/************************************************************************
 * AIDE - Automata Identification Engine
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     	-Date:  Change
 ************************************************************************/

using System;
using SMLib.Automata.MM;
using SMLib.Automata.Base;

namespace AIDE.Filters.NFMs
{
	/// <summary>
	/// Make the system input enables or specify the first 
	/// not-enabled action explicitly.
	/// <remarks>
	/// In several cases, not showing the not-enabled action makes the 
	/// conformance testing hard.
	/// </remarks>
	/// </summary>
	public class Filter_MM_InputEnabler: IBlackBox_MM
	{
		IBlackBox_MM sul;
		StringSymbol NOK, NOTTING;
		bool trapped;
		
		
		/// <summary>
		/// Initializes a new instance of the <see cref="AIDE.Filters.NFMs.Filter_MM_InputEnabler"/> class.
		/// </summary>
		/// <param name='sul'>
		/// The system under learning
		/// </param>
		/// <param name='trappedStateIsInputEnabled'>
		/// Trapped state is input enabled?
		/// </param>
		public Filter_MM_InputEnabler (IBlackBox_MM sul, bool trappedStateIsInputEnabled=false)
		{
			NOK = new StringSymbol ("NOK");
			
			if (trappedStateIsInputEnabled)
				NOTTING = new StringSymbol ("NOK");
			else 
				NOTTING = null;
			
			this.sul = sul;
		}
		
		
		#region IBlackBox_MM implementation
		public void Reset ()
		{
			trapped = false;
			sul.Reset ();
		}

		public ISymbol Step (ISymbol input)
		{
			if (trapped)
			{
				return NOTTING;
			}
			
			ISymbol output = sul.Step (input);
			//Console.Write("*"+output+"*");
			if (output == null) {
				//Console.WriteLine("Trapped!------");
				trapped = true;
				return NOK;
			} else
				return output;			
		}

		public Alphabet InputAlphabet {
			get {
				return sul.InputAlphabet;
			}
		}
		#endregion
	}
}

